<title>消息配置表</title>
<!--当前位置开始-->
<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <script type="text/html" template lay-done="layui.data.updateMainBreadcrumb();">
        </script>
    </div>
</div>
<!--当前位置结束-->
<style>
    /* 重写样式 */
</style>
<script type="text/html" template lay-type="Post" lay-url="{{ layui.setter.apiUrl }}Api/CoreCmsMessageCenter/GetIndex" lay-done="layui.data.done(d);">
</script>
<div class="table-body">
    <table id="LAY-app-CoreCmsMessageCenter-tableBox" lay-filter="LAY-app-CoreCmsMessageCenter-tableBox"></table>
</div>

<script>
    var indexData;
    var debug = layui.setter.debug;
    layui.data.done = function (d) {
        //开启调试情况下获取接口赋值数据
        if (debug) { console.log(d); }

        indexData = d.data;
        layui.use(['index', 'table', 'laydate', 'util', 'coreHelper'],
            function () {
                var $ = layui.$
                    , admin = layui.admin
                    , table = layui.table
                    , form = layui.form
                    , laydate = layui.laydate
                    , setter = layui.setter
                    , coreHelper = layui.coreHelper
                    , util = layui.util
                    , view = layui.view;

                //重载form
                form.render();
                var searchwhere;
                //监听搜索
                form.on('submit(LAY-app-CoreCmsMessageCenter-search)',
                    function (data) {
                        var field = data.field;
                        searchwhere = field;
                        //执行重载
                        table.reloadData('LAY-app-CoreCmsMessageCenter-tableBox', { where: field });
                    });
                //数据绑定
                table.render({
                    elem: '#LAY-app-CoreCmsMessageCenter-tableBox',
                    url: layui.setter.apiUrl + 'Api/CoreCmsMessageCenter/GetPageList',
                    method: 'POST',
                    defaultToolbar: ['filter', 'print', 'exports'],
                    height: 'full-127',//无面包屑127,搜索框189,1行62
                    page: false,
                    limit: 30,
                    limits: [10, 15, 20, 25, 30, 50, 100, 200],
                    text: { none: '暂无相关数据' },
                    cols: [
                        [
                            //{ type: "checkbox", fixed: "left" },
                            { field: 'id', title: '序列', width: 60, sort: false },
                            {
                                field: 'code', title: '编码', sort: false, templet: function (data) {
                                    for (var i = 0; i < d.data.platformMessageTypes.length; i++) {
                                        if (data.code == d.data.platformMessageTypes[i].title) {
                                            return d.data.platformMessageTypes[i].description +
                                                '(' +
                                                d.data.platformMessageTypes[i].title +
                                                ')';
                                        }
                                    }

                                }
                            },
                            { field: 'isSms', title: '启用短信', templet: '#switch_isSms', sort: false, unresize: true },
                            { field: 'isMessage', title: '启用站内消息', templet: '#switch_isMessage', sort: false, unresize: true },
                            { field: 'isWxTempletMessage', title: '启用微信模板消息', templet: '#switch_isWxTempletMessage', sort: false, unresize: true },
                        ]
                    ]
                });

                layui.form.on('switch(switch_isSms)', function (obj) {
                    coreHelper.Post("Api/CoreCmsMessageCenter/DoSetisSms", { id: this.value, data: obj.elem.checked }, function (e) {
                        if (debug) { console.log(e); } //开启调试返回数据
                        //table.reloadData('LAY-app-CoreCmsMessageCenter-tableBox');
                        layer.msg(e.msg);
                    });
                });

                layui.form.on('switch(switch_isMessage)', function (obj) {
                    coreHelper.Post("Api/CoreCmsMessageCenter/DoSetisMessage", { id: this.value, data: obj.elem.checked }, function (e) {
                        if (debug) { console.log(e); } //开启调试返回数据
                        //table.reloadData('LAY-app-CoreCmsMessageCenter-tableBox');
                        layer.msg(e.msg);
                    });
                });

                layui.form.on('switch(switch_isWxTempletMessage)', function (obj) {
                    coreHelper.Post("Api/CoreCmsMessageCenter/DoSetisWxTempletMessage", { id: this.value, data: obj.elem.checked }, function (e) {
                        if (debug) { console.log(e); } //开启调试返回数据
                        //table.reloadData('LAY-app-CoreCmsMessageCenter-tableBox');
                        layer.msg(e.msg);
                    });
                });

            });
    };
</script>

<!--设置启用短信-->
<script type="text/html" id="switch_isSms">
    <input type="checkbox" name="switch_isSms" value="{{d.id}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="switch_isSms" {{ d.isSms ? 'checked' : '' }}>
</script>

<!--设置启用站内消息-->
<script type="text/html" id="switch_isMessage">
    {{#  if(d.code != 'SellerOrderNotice'){ }}
    <input type="checkbox" name="switch_isMessage" value="{{d.id}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="switch_isMessage" {{ d.isMessage ? 'checked' : '' }}>
    {{#  } }}
</script>

<!--设置启用微信模板消息-->
<script type="text/html" id="switch_isWxTempletMessage">
    {{#  if(d.code == 'OrderPayed' || d.code == 'DeliveryNotice' || d.code == 'RemindOrderPay'){ }}
    <input type="checkbox" name="switch_isWxTempletMessage" value="{{d.id}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="switch_isWxTempletMessage" {{ d.isWxTempletMessage ? 'checked' : '' }}>
    {{#  } }}
</script>